﻿/*
 * File: PortalEditWindow.cs
 * Developer : Brent Larsen (brentoboy@gmail.com)
 * Date: 2011-AUG-9
 * Copyright (c) 2011 Brent Larsen.
 * Distributed under the terms of the GPL v3
 *  
 * This file is part of GenX-RPG
 * http://code.google.com/p/genx-rpg/ 
 * 
 * GenX-RPG is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GenX-RPG is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with GenX-RPG.  If not, see <http://www.gnu.org/licenses/>.
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Rpg.Editor
{
    public partial class PortalEditWindow : Form
    {
        public Portal Portal;

        public PortalEditWindow()
        {
            InitializeComponent();
        }

        public PortalEditWindow(Portal portal, Dictionary<int, string> mapNames)
            :this()
        {
            System.Diagnostics.Debug.Assert(portal != null);
            this.Portal = portal;

            list_ToMap.DisplayMember = "Value";
            list_ToMap.ValueMember = "Key";
            list_ToMap.DataSource = mapNames.ToKvpList();

            this.Text = "Portal [ID: {0}]".f(portal.Id);

            lblFromMap.Text = mapNames[this.Portal.MapId];

            txt_X1.Text = this.Portal.X1.ToString();
            txt_X2.Text = this.Portal.X2.ToString();
            txt_Y1.Text = this.Portal.Y1.ToString();
            txt_Y2.Text = this.Portal.Y2.ToString();

            if (this.Portal.To_MapId > 0)
                list_ToMap.SelectedValue = this.Portal.To_MapId;

            txt_ToX1.Text = this.Portal.To_X1.ToString();
            txt_ToX2.Text = this.Portal.To_X2.ToString();
            txt_ToY1.Text = this.Portal.To_Y1.ToString();
            txt_ToY2.Text = this.Portal.To_Y2.ToString();
        }


        private void btnSave_Click(object sender, EventArgs e)
        {
            this.Portal.X1 = txt_X1.Text.AsInt() ?? 0;
            this.Portal.X2 = txt_X2.Text.AsInt() ?? 0;
            this.Portal.Y1 = txt_Y1.Text.AsInt() ?? 0;
            this.Portal.Y2 = txt_Y2.Text.AsInt() ?? 0;

            this.Portal.To_MapId = list_ToMap.SelectedValue.AsInt() ?? 0;

            this.Portal.To_X1 = txt_ToX1.Text.AsInt() ?? 0;
            this.Portal.To_X2 = txt_ToX2.Text.AsInt() ?? 0;
            this.Portal.To_Y1 = txt_ToY1.Text.AsInt() ?? 0;
            this.Portal.To_Y2 = txt_ToY2.Text.AsInt() ?? 0;

            this.Close();
        }
    }
}
